package com.letoo.dragon.core.service.impl;

import java.io.File;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.letoo.dragon.common.utils.OssUtils;
import com.letoo.dragon.core.service.AliyunOssService;

/**
 * 阿里云OSS云存储服务接口实现
 * 
 * @author: dengjie
 */
@Service("aliyunOssService")
public class AliyunOssServiceImpl implements AliyunOssService {

    @Value("${aliyun.oss.endpoint}")
    private String endpoint;

    @Value("${aliyun.oss.accessKeyId}")
    private String accessKeyId;

    @Value("${aliyun.oss.accessKeySecret}")
    private String accessKeySecret;

    @Override
    public boolean uploadFile(String bucketName, String fileName, File file) {
        return OssUtils.uploadFile(endpoint, accessKeyId, accessKeySecret, bucketName, fileName, file);
    }

    @Override
    public boolean updateFile(String bucketName, String fileName, File file) {
        return OssUtils.updateFile(endpoint, accessKeyId, accessKeySecret, bucketName, fileName, file);
    }

    @Override
    public boolean replaceFile(String bucketName, String oldFileName, String newFileName, File file) {
        return OssUtils.replaceFile(endpoint, accessKeyId, accessKeySecret, bucketName, oldFileName, newFileName, file);
    }

    @Override
    public boolean deleteFile(String bucketName, String fileName) {
        return OssUtils.deleteFile(endpoint, accessKeyId, accessKeySecret, bucketName, fileName);
    }

    @Override
    public int batchDeleteFile(String bucketName, List<String> fileNames) {
        int count = OssUtils.batchDeleteFile(endpoint, accessKeyId, accessKeySecret, bucketName, fileNames);
        return count;
    }

}
